/*******************************************************************************
GControl.h

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2009-08-28

	Copyright (C) 2009
	All rights reserved.
	
*******************************************************************************/

#ifndef _GCONTROL_H_
#define _GCONTROL_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "GEngine.h"
#include "GSprite.h"

class GControl : public GObject
{
public:
	GControl();
	virtual ~GControl();

	BOOL Create(GSight* pSight, GControl* pParent, UINT nID);

	virtual void OnDraw(GDC* pDC);
	virtual bool IsVisible()const;

	virtual void Update(UINT nMillisecond);

	virtual BOOL GetPos(POS& refPos)const;
	virtual BOOL GetBox(BOX& refBox)const;
	virtual BOOL GetCxy(CXY& refCxy)const;

	virtual SINT HitTest(int x, int y)const;

	virtual GControl* NewCtrl(SceneDat::INT nType)const;

	PMRV	ProcMsg(GMsg& refMsg);

protected:
	const BYTE*	m_pBase;
	const void* m_pThis;

	struct GCTRL
	{
		union
		{
			GObject*	pObject;
			GSprite*	pSprite;
			GControl*	pControl;
			GButton*	pButton;
			GProgress*	pProgress;
			GTabHead*	pTabHead;
			GTabView*	pTabView;
		};
	};

	GCTRL*	m_pCtrls;

	bool	m_bEnable;

	UINT	m_nCtrlId;

protected:
	GControl*	m_pParent;
	
	friend class GDialog;

	virtual BOOL InitItem(GSight* pSight, GObject* pItem, UINT nID);
	virtual BOOL DataBind(GSight* pSight, const BYTE* pBase, SceneDat::PTR ptr);
};

class GDlgBox : public GControl
{
public:
	GDlgBox();
	virtual ~GDlgBox();

	PMRV ProcMsg(GMsg& refMsg);
};

class GButton : public GControl
{
public:
	GButton();
	virtual ~GButton();

	PMRV ProcMsg(GMsg& refMsg);

protected:
	void OnPressed(bool bTrue);
};


class GCheckBox : public GControl
{
public:
	GCheckBox();
	virtual ~GCheckBox();

	PMRV ProcMsg(GMsg& refMsg);

	bool IsChecked()const;
	bool SetCheck(bool bCheck);
	bool IsEnable()const;
	bool SetEnable(bool bEnable);

protected:
	bool	m_bChecked;
};


class GListBox : public GControl
{
public:
	GListBox();
	virtual ~GListBox();
};

class GProgress : public GControl
{
public:
	GProgress();
	virtual ~GProgress();

	SINT GetPos()const;
	SINT SetPos(SINT nPos);

protected:
	SINT m_nPos;

	virtual void OnDraw(GDC* pDC);

};

class GEditor : public GControl
{
public:
	GEditor();
	virtual ~GEditor();

	PMRV	ProcMsg(GMsg& refMsg);

	LPCTSTR	GetText(SINT* pnText = NULL)const;
	BOOL	SetText(LPCTSTR pText, SINT nText);

	SINT	SetType(SINT nType, SINT nMaxLength = 0);
	BOOL	SetCxy(SINT cx, SINT cy);
	GFont*	SetFont(GFont* pFont);
	COLOR	SetColor(COLOR color);

	virtual BOOL GetCxy(CXY& refCxy)const;

protected:
	FOCUS_EDIT	m_edit;
	SINT		m_nFocus;

	BOOL		m_bNew;
	GFont*		m_pFont;
	GText*		m_pText;

	virtual void OnDraw(GDC* pDC);
	virtual void Update(UINT nMillisecond);

	void	InsertTail(TCHAR c);
	void	DeleteTail(SINT nTail = 1);
};

class GTabHead : public GControl
{
public:
	GTabHead();
	virtual ~GTabHead();

	SINT	GetTab()const;
	SINT	SetTab(SINT nTab);
	SINT	GetActive()const;
	SINT	SetActive(SINT nAct);

	PMRV	ProcMsg(GMsg& refMsg);

	SINT	HitTest(int x, int y)const;

protected:
	SINT	m_nTab;
	SINT	m_nActive;

	virtual void OnDraw(GDC* pDC);

};

class GTabView : public GControl
{
public:
	GTabView();
	virtual ~GTabView();

	SINT	GetActive()const;
	SINT	SetActive(SINT nAct);

	PMRV	ProcMsg(GMsg& refMsg);

protected:
	friend class GControl;
	virtual BOOL DataBind(GSight* pSight, const BYTE* pBase, SceneDat::PTR ptr);

};


#endif//_GCONTROL_H_
